//
//  XJCommunitySearchResultView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/7/6.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  社区搜索结果view

#import "XJCommunitySearchResultView.h"
#import "XJCommunitySearchResultCell.h"

@interface XJCommunitySearchResultView()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tv;

@end

@implementation XJCommunitySearchResultView

#pragma mark - 一 lazy
- (UITableView *)tv {
    if (!_tv) {
        _tv = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tv.dataSource = self;
        _tv.delegate = self;
        
        NSString *className = NSStringFromClass([XJCommunitySearchResultCell class]);
        UINib *nib = [UINib nibWithNibName:className bundle:nil];
        [_tv registerNib:nib forCellReuseIdentifier:className];
    
        _tv.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tv.tableFooterView = [UIView new];
    }
    return _tv;
}

#pragma mark - 一 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    self.tv.frame = self.bounds;
    [self addSubview:self.tv];
}

#pragma mark - 二  layout


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *className = NSStringFromClass([XJCommunitySearchResultCell class]);

    
    XJCommunitySearchResultCell *cell = [tableView dequeueReusableCellWithIdentifier:className];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    XJCommunityModel *model = self.dataArray[indexPath.row];
    cell.model = model;
    
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    XJCommunityModel *model = self.dataArray[indexPath.row];
    XJLog(@"%@",model);
    
    if (self.communitySearchResultViewDidSelectCellBlock) {
        self.communitySearchResultViewDidSelectCellBlock(model);
    }
}

- (void)cmtSearchResultViewReload {
    [self.tv reloadData];
}


@end
